package cn.itsource.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
public class CookieController {

    @GetMapping("/addCookie")
    public void add(HttpServletResponse response){
        //创建cookie对象
        Cookie cookie = new Cookie("zs", "123");
        //把创建好的cookie响应给浏览器
        response.addCookie(cookie);
    }


    @GetMapping("/getCookie")
    public void getCookie(HttpServletRequest request,HttpServletResponse response){
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            System.out.println(cookie.getName()+"   "+cookie.getValue());
        }
    }
}
